#!/bin/bash
#
# $Id$
# Copyright 2009 Google Inc. All Rights Reserved.
# Author: arb@google.com (Anthony Baxter)

SAT=$1
SERIES=$2
YEAR=2009
# 2km, 1km, 500m, 250m
RES=500m
EXTRA="&vectors=fires+coast"

DIR=${YEAR}${SERIES}-${SAT}-${RES}
mkdir $DIR
mkdir $DIR/metadata
for image in Tasmania Australia3 Australia5 Australia6
do
  wget -c "http://rapidfire.sci.gsfc.nasa.gov/subsets/?subset=${image}.${YEAR}${SERIES}.${SAT}.${RES}.tif&vectors=fires+coast"
  mv "index.html?subset=${image}.${YEAR}${SERIES}.${SAT}.${RES}.tif${EXTRA}" \
    "${DIR}/${YEAR}${SERIES}.${image}.${RES}.tiff"
  wget "http://rapidfire.sci.gsfc.nasa.gov/subsets/?subset=${image}.${YEAR}${SERIES}.${SAT}.${RES}.txt"
  mv "index.html?subset=${image}.${YEAR}${SERIES}.${SAT}.${RES}.txt" \
    "${DIR}/metadata/${image}.txt"
done

gdal_merge.py -o ${DIR}/combined.tiff ${DIR}/${YEAR}*
python ./metadata.py ${DIR}
cd ${DIR}
gdal_translate -projwin 135.0 -28.0 154.0 -44.0 combined.tiff cropped.tiff
gdal2tiles.py -z 5-9 cropped.tiff tiles
cd ../
./crusher.sh ${DIR}
cp ${DIR}/datestamp.txt ../web/zips/tiles/nasa/
